<template>
  <view class="content">
    <view class="box">
      <text class="illustrate">
        请确认以下信息是你本人的数据，并补充确认信息。如确认属实，我们将为你进行数据合并
      </text>
      <view class="name">
        {{ name }}
      </view>
      <view class="introduction">
        <view v-if="enterprise">
          就职于&nbsp;
          <text>
            {{ enterprise }}
          </text>
        </view>
        <view v-if="honor">
          曾获得&nbsp;
          <text> {{ honor }} </text>&nbsp;荣誉
        </view>
      </view>
    </view>
    <br />
    <br />
    <view class="box">
      <text class="header-title min">补充确认信息</text>
      <uni-list :border="false">
        <uni-list-item title="所任岗位">
          <template v-slot:footer>
            <input
              style="text-align: right"
              :inputBorder="false"
              class="uni-input"
              placeholder="请输入所任岗位"
              v-model="post"
            />
          </template>
        </uni-list-item>
      </uni-list>
    </view>
    <br />
    <br />
    <view class="box">
      <text class="header-title min">荣誉核实确认</text>
      <uni-list
        v-for="(item, index) in information"
        :key="item.id"
        :border="false"
      >
        <uni-list-item :title="`关于${item.awards}：`"> </uni-list-item>
        <uni-list-item
          title="授予单位"
          :rightText="item.grantUnit ? item.grantUnit : '请选择'"
          @click="unitClick(index)"
          link
        >
          <template v-slot:footer>
            <picker
              @change="companyChange"
              :value="item.grantUnit"
              :range="companyData"
              range-key="value"
            >
              <view class="uni-input">{{
                item.grantUnit ? item.grantUnit : "请选择"
              }}</view>
            </picker>
          </template>
        </uni-list-item>
        <uni-list-item title="授予时间" link @click="createTimeClick(index)">
          <template v-slot:footer>
            <picker
              @change="timeChange"
              :value="item.grantTime"
              :range="timeData"
              range-key="value"
            >
              <view class="uni-input">{{
                item.grantTime ? item.grantTime : "请选择"
              }}</view>
            </picker>
          </template>
        </uni-list-item>
      </uni-list>
    </view>
    <view class="btn-box">
      <text class="btn-botton" @click="submit"> 提交审核 </text>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted, getCurrentInstance } from "vue";
import { getUserInfoApi } from "@/api/public";

import {
  getUserMergeDataApi,
  getGrantingTimeList,
  getGrantingUnitList,
  addUserMergeDataCheck,
} from "@/api/index/index.js";
const name = ref("");
const enterprise = ref("");
const honor = ref("");
const post = ref("");
const information = ref([]);
const companyData = ref([]);
const timeData = ref([]);
const callIndex = ref();
const { proxy } = getCurrentInstance();
function getUserInfoData() {
  getUserInfoApi().then((res) => {
    name.value = res.data.realName;
    enterprise.value = res.data.enterpriseName;
    honor.value = res.data.personalHonor;
  });
  getUserMergeDataApi().then((res) => {
    information.value = res.data;
  });
  getGrantingTimeList().then((res) => {
    timeData.value = res.data.map((o) => {
      return {
        text: o,
        value: o,
      };
    });
  });
  getGrantingUnitList().then((res) => {
    companyData.value = res.data.map((o) => {
      return {
        text: o,
        value: o,
      };
    });
  });
}
function unitClick(index) {
  callIndex.value = index;
  // companyShow.value = true;
}
function companyChange(data) {
  information.value[callIndex.value].grantUnit =
    companyData.value[data.detail.value].value;
}
function createTimeClick(index) {
  callIndex.value = index;
}
function timeChange(data) {
  information.value[callIndex.value].grantTime =
    timeData.value[data.detail.value].value;
}
function submit() {
  console.log("post.value", post.value);
  if (post.value == "") {
    uni.showToast({
      icon: "none",
      title: "请输入所任岗位！",
    });
  } else {
    let data = {
      job: post.value,
      userHonorImportDataCheckList: information.value.map((o) => {
        return {
          id: o.id,
          grantTime: o.grantTime,
          honorName: o.honorName,
          grantUnit: o.grantUnit,
        };
      }),
    };
    addUserMergeDataCheck(data).then((res) => {
      console.log(res);
      if (res.code == 200) {
        uni.showToast({
          title: "提交成功",
          icon: "success",
        });
        uni.switchTab({
          url: "/pages/index/index",
        });
      }
    });
  }
}
onMounted(() => {
  getUserInfoData();
});
</script>

<style lang="less" scoped>
@import "@/static/style/global.less";
.content {
  min-height: 93vh;
  padding-bottom: 150rpx;
  .illustrate {
    font-size: @font-size-23;
    color: @color-label;
    font-weight: 400;
    font-family: "ali";
  }
  .name {
    font-size: @font-size-39;
    color: @color-green;
    font-weight: 500;
    font-family: "ali";
    margin: 25rpx 0;
  }
  .introduction {
    font-size: @font-size-23;
    color: @color-black;
    font-weight: 400;
    font-family: "ali";
    margin-bottom: 10rpx;
    text {
      color: @color-blue;
    }
  }
  .btn-botton {
    width: 80vw;
  }
}
</style>
